package com.visec.hdy.task;

import java.util.Map;

import com.visec.hdy.config.PCVHandle;
import com.visec.hdy.sync.ftp.code.FtpSendManager;
import com.visec.hdy.sync.ftp.config.FtpClientModel;
import com.visec.hdy.sync.ftp.config.FtpClientModelCV;
import com.visec.hdy.sync.ftp.config.FtpSendClient;
import com.visec.hdy.sync.ftp.config.SyncSendConfig;
import com.visec.hdy.transmission.ftp.config.FtpModel;
import com.visec.hdy.transmission.ftp.config.FtpModelCV;
import com.visec.hdy.transmission.socket.config.SocketModel;
import com.visec.hdy.transmission.socket.config.TSocketModelCV;

public class SyncClient {
//	java -Djava.ext.dirs=/root/ftpjar -jar ftptask.jar -stip 172.26.78.2 -stport 4401 -fip 192.168.10.4 -fuser admin -fpassword 123456 -ftpId sb -task client_add -exportPort 4402 
//	public static void main(String[] args) {
//		args = new String[] { "-stip", "192.168.10.165", "-stport", "4401", "-fip", "192.168.0.152", "-fuser", "admin",
//				"-fpassword", "123456", "-ftpId", "sb" };
//		start(ParameterHandle.strArryToMap(args));
//	}

	public static void start(Map<String, String> m) {
		// args = new String[] { "-stip", "192.168.10.165", "-stport", "4401",
		// "-fip", "192.168.0.152", "-fuser", "admin",
		// "-fpassword", "123456", "-ftpId", "aaa" };

		PCVHandle pcv = new PCVHandle(new TSocketModelCV(), new FtpModelCV(), new FtpClientModelCV());
		pcv.conversion(m);
		SocketModel socket = pcv.getTarget(SocketModel.class);
		FtpModel ftp = pcv.getTarget(FtpModel.class);
		FtpClientModel fcm = pcv.getTarget(FtpClientModel.class);

		if (socket.getIp() == null) {
			System.out.println("are you sb?please send server ip by -stip");
			return;
		}
		if (socket.getPort() == 0) {
			System.out.println("are you 2b?please send server ip by -stport");
			return;
		}

		SyncSendConfig fsc = new SyncSendConfig(fcm.getTools(), new FtpSendClient(ftp, socket), fcm.getSleepTime(),
				fcm.getFtpId(), socket.getBufferSize(), fcm.isSave());

		FtpSendManager instance = FtpSendManager.getInstance(fsc, socket);

		System.out.println("start client,target server--stip:" + socket.getIp() + ",-stport:" + socket.getPort()
				+ ",-stcharset:" + socket.getCharset() + ",-stbufferSize:" + socket.getBufferSize());

		instance.start();

	}

}
